package cn.swh.guguanjia.mapper;

import cn.swh.guguanjia.entity.SysUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

@org.apache.ibatis.annotations.Mapper
public interface SysUserMapper extends Mapper<SysUser> {
    @SelectProvider(type =SysUserProvider.class ,method = "selectPage")
    List<SysUser> selectPage(Map<String,Object> map);

    @Select("SELECT " +
            " su.id,su.name  " +
            "FROM " +
            " sys_user_role sur, " +
            " sys_user su  " +
            "WHERE " +
            " su.del_flag = 0  " +
            " AND sur.role_id = #{rid}  " +
            " AND sur.user_id = su.id")
    List<SysUser> selectById(long rid);

    @Select("SELECT  name,id  FROM  sys_user sus  " +
            "WHERE  sus.office_id = #{oid}  " +
            " AND NOT EXISTS ( SELECT 1 FROM sys_user_role sur WHERE sur.role_id = #{rid} AND sus.id = sur.user_id )")
    List<SysUser> selectNoRole(@Param("rid") long rid, @Param("oid") long oid);
}